﻿var playbar = (function () {
    // 初始化

    function playbar() {
        // 属性
        //this.app = options.app;
        this.slider = {};
        this.timer = {};
        this.value = 0;
        this.repeat = true;
        this.interval = 5000;
        
    }
    //
    //初始化
    playbar.prototype.resize = function (options) {


    }
    playbar.prototype.init = function (options) {
        var that = this;
        //根据当时时间，构建列表
        //开始时间是当天的0点，
        //当前时间
        //结束时间是但前时间+168小时
        //播放工具条
        var now = moment();
        var dayweekcn = ["日", "一", "二", "三", "四", "五", "六"];
        var currentday = moment().format("YYYY-MM-DD 00:00:00");
        var currenthour = moment().hour();
        var maxhour = currenthour + 168;

        var tickvalues = [0, 24, 48, 72, 96, 120, 144, 168, maxhour];
        var ticklabels = [];
        for (var i = 0; i < 8; i++) {
            var t = moment().add(i, 'd');
            //获取星期：
            var week = t.weekday();
            var day = t.date();
            ticklabels.push("周" + dayweekcn[week] + " " + day);
        }

        this.slider = $('#' + options.id).slider({
            tooltip: 'always',
            ticks: tickvalues,
            ticks_labels: ticklabels,
            formatter: function (value) {
                var nowtime = moment(currentday, "YYYY-MM-DD 00:00:00").add(value, "h");
                return '周' + dayweekcn[nowtime.weekday()] + " " + nowtime.date() + ' - ' + nowtime.hour() + ":00";
            }
        });
        //构建时间轴上的提示

        //this.slider.slider("setAttribute","ticks",tickvalues);		
        this.slider.slider("setValue", currenthour);
        //this.slider.setAttribute("ticks_labels", []);
        this.slider.on('change', function (e) {
            var newvalue = e.value.newValue;
            var b = e.value.oldValue;
            //获取时间
            var nowtime = moment(currentday, "YYYY-MM-DD 00:00:00").add(newvalue, "h");
            //that.app.time = nowtime.format("YYYY-MM-DD HH:00:00");
            //刷新数据
            //that.app.refresh();
        });
    };
    playbar.prototype.start = function (options) {
        var that = this;
        //更改全局时间
        //是否重复，
        //时间间隔
        function _setvalue() {
            if (that.value < 168) {
                that.value++;
            } else {
                if (that.repeat) {
                    //如果重复
                    that.value = 0;
                } else {
                    //不需要重复
                    that.stop();
                }
            }
            that.slider.slider("setValue", that.value, false, true);

        }
        this.timer = window.setInterval(_setvalue, that.interval)
    };

    playbar.prototype.stop = function (options) {
        window.clearInterval(this.timer);
    };

    // 返回
    return playbar;
})();


 